<?php 

    $url= new Url();
    $current_url = Common::getCurrentUrl();
    $path_paging = strpos($current_url,'?') !==false ? $current_url.'&' : $current_url.'?';
    $path_paging = str_replace("?page=".$page."&","?",$path_paging);
    $path_paging = str_replace("&page=".$page."&","&",$path_paging);
?>
<div class="main clearfix">
    <div class="Tabs clearfix">
        <ul class="clearfix">
            <li><a href="<?php echo Url::createUrl("customerCare/index"); ?>" class="active" ><span>Báo lỗi</span></a></li>
            <li><a href="<?php echo Url::createUrl("customerCare/logsms"); ?>"><span>Log Sms</span></a></li>
            <li><a href="<?php echo Url::createUrl("customerCare/logcard"); ?>" ><span>Log Card</span></a></li> 
        </ul>                
    </div>
    <div class="box clearfix bottom30">       
        <form action="" method="get">
            <ul class="form4">
                <li class="clearfix"><label><strong>Ngày tháng </strong>:</label>
                    <div class="filltext">
                        <?php
                            $this->widget(
                            "zii.widgets.jui.CJuiDatePicker"
                            , array(
                            "name"=>"from_date"
                            , "id"=>"from_date"
                            , "value"=>$from_date                                                                
                            , "options"=> array(
                            'showAnim' => 'fold'
                            , 'dateFormat' => 'dd-mm-yy'
                            , 'changeYear' => 'true'
                            , 'changeMonth' => 'true'
                            , 'showOn' => 'both'
                            , 'buttonText' => '<input type="button" name="" value="" class="ic-date">'
                            )
                            , 'htmlOptions' => array(
                            'style' => 'width:170px'
                            , 'class' => 'form'
                            )
                            )
                            );
                        ?>                                       
                        &nbsp;đến ngày &nbsp; 
                        <?php
                            $this->widget(
                            "zii.widgets.jui.CJuiDatePicker"
                            , array(
                            "name"=>"to_date"
                            , "id"=>"to_date"
                            , "value"=>$to_date
                            , "options"=> array(
                            'showAnim' => 'fold'
                            , 'dateFormat' => 'dd-mm-yy'
                            , 'changeYear' => 'true'
                            , 'changeMonth' => 'true'
                            , 'showOn' => 'both'
                            , 'buttonText' => '<input type="button" name="" value="" class="ic-date">'
                            )
                            , 'htmlOptions' => array(
                            'style' => 'width:170px'
                            , 'class' => 'form'
                            )
                            )
                            );
                        ?>
                    </div>
                </li>
                <li class="clearfix"><label><strong>Tài khoản </strong>:</label>
                    <div class="filltext">
                        <input name="username" type="text" style="width:331px;margin-right:28px" value="<?php if(isset($username)){ echo $username;} ?>">
                    </div>
                </li>


                <li class="clearfix"><label>&nbsp;</label>
                    <div class="filltext">
                        <input type="submit" value=" Tìm kiếm" class="btn-bigblue"> 
                    </div>
                </li>

            </ul>
        </form>
    </div>
    <div class="box">
        <div class="fillter clearfix">
            <div class="fl">Tìm thấy <strong class="clred"><?php echo $count ?></strong> kết quả trong <strong class="clred"><?php echo $max_page; ?></strong> trang</div>
            <div class="fr">
                <ul class="paging">
                     <?php echo Paging::show_paging_cp($max_page,$page,$path_paging); ?>   
                </ul>
            </div>
        </div>
        <div class="table clearfix">
            <table width="100%" cellspacing="0" cellpadding="0" border="0">
                <tbody>
                    <tr class="bg-grey">
                        <td width="5%">STT</td>
                        <td width="5%"><strong>Tài khoản</strong></td>
                        <td width="35%"><strong>Nội dung</strong></td>
                        <td width="10%"><strong>Ngày gửi</strong></td>
                        <td width="35%"><strong>Trả lời</strong></td>
                    </tr>
                    <?php foreach($data as $key =>$value){ ?>
                    <tr>
                        <td class="middle"><?php echo $key+1; ?></td>
                        <td class="middle"><strong class="clblue"><?php echo $value['username'];  ?></strong></td>
                        <td class="middle"><textarea style="width:95%; height: 100px"><?php echo $value['content']; ?></textarea></td>
                        <td class="middle"><?php echo date("H:i:s d-m-Y",$value['create_date']); ?></td>
                        <td class="middle"><textarea  id="tea_<?php echo $value['userId']; ?>" style="width: 80%;height: 100px;display: none" ></textarea><a class="button" id="reply_<?php echo $value['userId']; ?>" onclick="show(<?php echo $value['userId']; ?>)" href="javascript:void(0)">Trả lời</a><a id="send_<?php echo $value['userId']; ?>" style="display: none;" href="javascript:void(0)" onclick="ajaxReply(<?php echo $value['userId'];?>)" > | Gửi</a></td>
                    </tr>
                      
                    <?php } ?>
                </tbody>
            </table>
        </div>
        <div class="fillter clearfix">
            <div class="fr">
                <ul class="paging">
                     <?php echo Paging::show_paging_cp($max_page,$page,$path_paging); ?>   
                </ul>
            </div>
        </div>

    </div>
</div>
<script type="">
  function ajaxReply(id){
        var mes=$("#tea_"+id).val();
        var strUrl = "<?php echo Url::createUrl("customerCare/ajaxReply") ?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                mes : mes,
                id : id
            },
            success: function(msg){
                if(msg == 1){
                    alert('Gửi thành công');
                    location.reload();
                }else{
                    alert(msg);
                }
            }          
        });
    }
    function show(id){
        
        $("#tea_"+id).toggle("slow");
        $("#send_"+id).toggle("slow");
    }
</script>